package cmpe226.spring2011.project1;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import cmpe226.spring2011.project1.model.Quote;
import cmpe226.spring2011.project1.model.RecordDTO;
import cmpe226.spring2011.project1.model.Symbol;

/**
 * 2nd step in the 2-step process of converting raw datafiles into domain model POJOs.
 * Transforms RecordDTO maps into Symbols that hold Quotes.
 */
public class DataMapper {

	public static List<Symbol> transformToDomainObjects(Map<String, List<RecordDTO>> data) {
		List<Symbol> symlist = new ArrayList<Symbol>();
		for (Map.Entry<String, List<RecordDTO>> entry : data.entrySet()) {
			Symbol symbol = new Symbol();
			symbol.setSymbol(entry.getKey());
			
			for (RecordDTO record : entry.getValue()) {
				Quote quote = new Quote();
				quote.setAdjclose(record.getAdjClose());
				quote.setClose(record.getClose());
				quote.setDate(record.getDate());
				quote.setHigh(record.getHigh());
				quote.setLow(record.getLow());
				quote.setOpen(record.getOpen());
				quote.setVolume(record.getVolume());
				symbol.getQuotes().add(quote);
			}
			symlist.add(symbol);
		}
		return symlist;
	}
}
